#include "pch.h"
#include "GravityObject.h"

GravityObject::GravityObject(void):
	m_xSpeedLimit(10),
	m_ySpeedLimit(10),
	m_xSpeed(0),
	m_ySpeed(0),
	m_xGravity(0),
	m_yGravity(0.3),
	m_xLocation(0),
	m_yLocation(0)
{

}


GravityObject::~GravityObject(void)
{
}

void GravityObject::Update()
{
	m_xSpeed+=m_xGravity;
	m_ySpeed+=m_yGravity;
	if(abs(m_xSpeed)>m_xSpeedLimit)
	{
		m_xSpeed=m_xSpeedLimit*(m_xSpeed/abs(m_xSpeed));
	}
	if(abs(m_ySpeed)>m_ySpeedLimit)
	{
		m_ySpeed=m_ySpeedLimit*(m_ySpeed/abs(m_ySpeed));
	}
	m_xLocation+=m_xSpeed;
	m_yLocation+=m_ySpeed;

	if(m_yLocation>300)
	{
		m_ySpeed=0;
		m_yLocation=300;
	}
	if(m_xLocation<10)
	{
		m_xLocation=10;
	}

	if(m_xLocation>800)
	{
		m_xLocation=800;
	}

	RenderTransform.TranslateX=m_xLocation;
	RenderTransform.TranslateY=m_yLocation;
}

void GravityObject::Render(DisplayContext &dislpayEngine)
{
	ImageDisplayItem::Render(dislpayEngine);
}